package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {

    @Autowired
    private MemberDao memberDao;

    @Autowired
    private OrderDao orderDao;

    @Override
    public Map<String, Object> findAllBusinessData() throws Exception {
        //创建map集合进行数据的封装操作
        Map<String,Object> reportData = new HashMap<>();

        //获取到当前时间
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        reportData.put("reportDate",today);

        //查询今天新创建的用户数量
        Integer todayNewMember = memberDao.findMemberCountByDate(today);
        reportData.put("todayNewMember",todayNewMember);

        //查询总用户数量
        Integer totalMember = memberDao.findMemberTotalCount();
        reportData.put("totalMember",totalMember);

        //获取到当前时间星期一的日期
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //查询这个星期增加的新用户数量
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(thisWeekMonday);
        reportData.put("thisWeekNewMember",thisWeekNewMember);

        //获取到当前月的第一天
        String thisFirstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(thisFirstDay4ThisMonth);
        reportData.put("thisMonthNewMember",thisMonthNewMember);

        //获取到今天预约的数量
        Integer todayOrderNumber = orderDao.findOrderCountByDate(today);
        reportData.put("todayOrderNumber",todayOrderNumber);

        //获取今天的到诊数量
        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(today);
        reportData.put("todayVisitsNumber",todayVisitsNumber);

        //获取到这个星期的预约数量
        Integer thisWeekOrderNumber = orderDao.findOrderCountAfterDate(thisWeekMonday);
        reportData.put("thisWeekOrderNumber",thisWeekOrderNumber);

        //获取到这个星期的到诊数量
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(thisWeekMonday);
        reportData.put("thisWeekVisitsNumber",thisWeekVisitsNumber);

        //获取到这个月的预约数量
        Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(thisFirstDay4ThisMonth);
        reportData.put("thisMonthOrderNumber",thisMonthOrderNumber);

        //获取到这个月的到诊数量
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(thisFirstDay4ThisMonth);
        reportData.put("thisMonthVisitsNumber",thisMonthVisitsNumber);



        //查询热门套餐
        List<Map> hotSetmeal = orderDao.findHotSetmeal();
        reportData.put("hotSetmeal",hotSetmeal);

        return reportData;
    }
}
